/*
 *  NoDelay - Copyright (C) 2006 chr15 (chr15@mail.com)
 *  NoDelay Source code at http://userscripts.org/scripts/show/6499
 *    NoDelay is designed to be wildcard filtered through greasemonkey, and then further filtering is imposed at the 
 *    script level to allow a far greater control of script processing.
 *    NoDelay handles any subdomain and prefix, if you wanted to do further processing on the domain prefix this is 
 *    also possible via the aDomain Array, as well as further processing of the path parameters via the aPath Array.
 *  History
 *    2006.11.24..Added more scripts, and Improved NoCountdown's "depositfiles.com" script          
 *        Included support for 
 *           http://www.filesend.net     -- Taken from NoCountdown
 *           http://www.depositfiles.com -- Taken from NoCountdown -- Modified script
 *           http://www.badongo.com      -- Taken from NoCountdown
 *           http://www.megaupload.com   -- Taken from NoCountdown
 *        Added support for 
 *           http://www.mihd.net
 *           http://www.icefile.net
 *           http://www.mytempdir.com
 *           http://www.bigupload.com
 *           http://www.yousendit.com
 *           http://www.live-share.com
 *           http://www.fileho.com
 *    2006.11.27..Added more scripts, and Improved Rapidshare Bundle's "rapidshare" script          
 *        Fixed http://www.megaupload.com - just wait for the script to start the download automatically
 *        Added support for 
 *           http://www.rapidshare.com
 *           http://www.rapidshare.de
 *           http://www.oxyshare.com
 *    2006.11.28..Added support for
 *           http://www.turboupload.com
 *           http://www.mooload.com
 *           http://www.icefile.com
 *           http://www.quicksharing.com
 *           http://www.verzend.be
 *           http://www.megashares.com
 *           ** Not Yet ** http://www.zupload.com
 *           http://www.ftp2share.com
 *           http://www.lix.in -- RapidShare
 *           http://www.filefactory.com
 *           http://www.sendspace.com
 *           http://www.yofreespace.com
 *    2006.12.07..Added support for
 *           http://www.gigasize.com
 *           http://www.ileech.net
 *           http://www.rsprotect.com
 *           http://www.mediafire.com
 *           http://www.zshare.net
 *           http://www.binfile.org
 *    2007.01.02..Added support for
 *           http://www.uploading.com
 *           http://www.easy-share.com
 *    2007.01.11..Added support for
 *           http://www.axifile.com
 *           http://www.sharebigfile.com
 *           http://www.megarotic.com
 *           http://www.looler.com
 *           http://www.megashares.com
 *           http://www.gulli.com
 *           http://www.hyperupload.com
 *           http://www.link-protector.com
 *           http://www.icefile.org
 *
 *    2007.05.25..Added support for
 *           http://www.flyupload.com
 *           http://www.mfile3.com
 *           http://www.filefront.com
 *           http://www.bravoshare.com
 *           http://*.urlcash.net
 *
 *    2007.05.30..Updated support for
 *           http://www.flyupload.com
 *
 *  NoDelay was inspired and is partly based on "NoCountdown!", and incorporates "Rapidshare Bundle" with some modifications.
 *  My thanks goes to Unbrained and Jillian for providing the original scripts, which NoDelay is based on.  
 *
 *    NoCountdown! - Copyright (C) 2006 Unbrained (josuicida@gmail.com)
 *    NoCountdown! Source code at http://userscripts.org/scripts/show/5949
 *
 *  Rapidshare Bundle was the source for the Rapidshare functions below, I added some changes to get the script working
 *    Rapidshare Bundle - Jillian
 *    Rapidshare Bundle Source code at http://userscripts.org/scripts/show/5907
 *
 *  This script is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU General Public
 *  License as published by the Free Software Foundation; either
 *  version 2 of the License, or (at your option) any later version.
 *
 *  This script is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *  General Public License for more details.
 *  http://www.gnu.org/copyleft/gpl.html
 */

// ==UserScript== 
// @name			  NoDelay
// @namespace   userscripts.org
// @author			chr15
// @description	Removes the delay in navigating to the download links on many upload sites (v1.3.20070529.1)
// @include			http://*badongo.com/*/file/*
// @include			http://*bigupload.com/*
// @include			http://*depositfiles.com/*/files/*
// @include			http://*filefactory.com/*
// @include			http://*fileho.com/download/*
// @include			http://*filesend.net/*
// @include			http://*ftp2share.com/*
// @include			http://*gigasize.com/formdownload.php
// @include			http://*icefile.com/*
// @include			http://*icefile.net/*
// @include			http://*live-share.com/*
// @include			http://*lix.in/*
// @include			http://*megashares.com/*
// @include			http://*megashare.com/*
// @include			http://*megaupload.com/*
// @include			http://*mihd.net/*
// @include			http://*mooload.com/new/file.php?file=*
// @include			http://*mytempdir.com/*
// @include			http://*rapidshare.de/*
// @include			http://*rapidshare.com/*
// @include			http://*oxyshare.com/*
// @include			http://*quicksharing.com/v/*
// @include			http://*sendspace.com/*
// @include			http://*turboupload.com/*
// @include			http://*verzend.be/v/*
// @include			http://*yofreespace.com/download.php?id=*
// @include			http://*yousendit.com/*
// @include			http://*ileech.net/*
// @include			http://*rsprotect.com/*
// @include			http://*mediafire.com/*
// @include			http://*zshare.net/download/*
// @include			http://*binfile.org/download.php?id=*
// @include			http://*uploading.com/*/files/*
// @include			http://*easy-share.com/*
// @include			http://*axifile.com/*
// @include			http://*sharebigfile.com/file/*
// @include			http://*megarotic.com*
// @include			http://*looler.com/file/*
// @include			http://*gulli.com/dl/files/*
// @include			http://*hyperupload.com/download/*
// @include			http://*link-protector.com/*
// @include			http://*icefile.org/*
// @include			http://*flyupload.com/get?*
// @include			http://*flyupload.com/thankyou?URL=*
// @include			http://*mfile3.com/transfer.php
// @include			http://files.filefront.com/*
// @include			http://*bravoshare.com/*
// @include			http://*.urlcash.net/
// NOT INCLUDED			http://*zupload.com/download.php?file=getfile&filepath=*

// ==/UserScript==

//***********************  //***********************
function closeWindow(){
  unsafeWindow.close();
}
//***********************
function getDomain(){
	var idx2 = location.href.indexOf("://"); 
	var urlLink2=location.href.substring(0, idx2+3);
	var sDomain = location.href.substring(idx2+3, 500);
	idx2 = sDomain.indexOf("/"); 
	return urlLink2+sDomain.substring(0, idx2);
}
//***********************
// Returns null if expr didn't match anything
function getFirstXPathResult(expr, node){
  if (!node) node = document;
  var res = document.evaluate(expr, node, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null);
  return res.singleNodeValue;
}
//***********************
function findClick(condFind, node){
	if (!node) node = document;
  var freeBtn = getFirstXPathResult(condFind, node);
  if (freeBtn) { freeBtn.click(); }
  return freeBtn;
}
//***********************
function delayFindHREF(delay, condFind, parentBool){
  unsafeWindow.setTimeout(
	  function() {
			try { 
			  var dataText = getFirstXPathResult(condFind);
			  if (!dataText) return;
			  if(parentBool) document.location=dataText.parentNode.href
			  else document.location=dataText.href; 
			} catch(e){}
	  }, delay);	
}
//***********************
var putTimerInTitle = true;
// Alerts the user when the wait between downloads is over
function waitUntilReady(idStr, delaySeconds, captionStr, download){
  try { 
	  var timeReady = new Date();
	  timeReady.setSeconds(timeReady.getSeconds() + delaySeconds);
	  waitTimeoff();
	} catch(e){ alert('waitUntilReady Exception'); }
	
	function waitTimeoff() {
    try { 
		  var now = new Date();
		  if (now < timeReady) {
		    var left = new Date(timeReady - now);
		    // Match hours only if not 00
		    var strTime = left.toUTCString().match(/(0[1-9]:)?\d\d:\d\d /)[0];
		    document.getElementById(idStr).textContent = strTime;
		    if (putTimerInTitle) document.title = captionStr+" (" + strTime + ")";
		    setTimeout(waitTimeoff, 1000);
		  }
		  else download();
    } catch(e){alert('waitTimeoff  Exception');}
  }
}
//***********************
function waitUntilReadyTest(idStr, delaySeconds, captionStr, download){
  try { 
	  var timeReady = new Date();
	  timeReady.setSeconds(timeReady.getSeconds() + delaySeconds);
	  waitTimeoff();
	} catch(e){ alert('waitUntilReady Exception'); }
	
	function waitTimeoff() {
    try { 
		  var now = new Date();
		  if (now < timeReady) {
		    var left = new Date(timeReady - now);
		    // Match hours only if not 00
		    var strTime = left.toUTCString().match(/(0[1-9]:)?\d\d:\d\d /)[0];
//			    var strTime = left.toUTCString().match(/(0[1-9]:)?\d\d:\d\d:\d\d /)[0];
		    document.getElementById(idStr).textContent = strTime;
		    alert(document.getElementById(idStr).textContent);
		    if (putTimerInTitle) document.title = captionStr+" (" + strTime + ")";
		    setTimeout(waitTimeoff, 1000);
//			    setTimeout(waitTimeoff, 100);
		  }
		  else download();
    } catch(e){alert('waitTimeoff  Exception');}
  }
}
//***********************  rapidshare_domain  //***********************
function rapidshare_domain_prepareDownloadLink(){
  var dlform = document.forms.namedItem("dl");
  if (!dlform) {
    GM_log("Something is wrong, the form named 'dl' should exist by now!");
    return;
  }
//  var imgCodeName="captcha";
  var imgCodeName="accesscode";
  var btn = dlform.elements.namedItem("actionstring"); // The submit button
  var url = dlform.action + "?actionstring=" + btn.value + "&"+imgCodeName+"=";
  btn.value = "create link";
  dlform.addEventListener("submit", createLink, true);
 // On submit, add captcha code and create the download link
  function createLink(evt) {
    evt.preventDefault(); // Prevent form submission
    var captcha = dlform.elements.namedItem(imgCodeName).value;
    if (captcha == "") {
      alert("You must enter the captcha code before the link can be created.");
      return;
    }
//    var fullurl = url + captcha;
    var fullurl = url + captcha.toUpperCase();
    dlform.innerHTML += "<a href='" + fullurl + "'><b>(alt) click to download</b></a>";
  }
}
//***********************
function rapidshare_domain_cleanDownloadPage(){
  var tdchild = getFirstXPathResult("//p[text() = 'You have requested the file ']");
  if (!tdchild) return;
  // In the TD element, clean everything from the bottom up to the ad.
  var ad = getFirstXPathResult("following-sibling::img", tdchild);
  if (ad) {
    var td = tdchild.parentNode;
    var i = td.childNodes.length - 1;
    while (td.removeChild(td.childNodes[i]) != ad) i--;
  }
  // Remove anything related to the upload form
  var ulform = getFirstXPathResult("//form[@name='ul']");
  var ulscript = getFirstXPathResult("preceding-sibling::script", ulform);
  var uliframe = getFirstXPathResult("//iframe[contains(@src, 'uploadid')]");
  if (ulform)    ulform.parentNode.removeChild(ulform);
  if (ulscript)  ulscript.parentNode.removeChild(ulscript);
  if (uliframe)  uliframe.parentNode.removeChild(uliframe);
}
//***********************
// Alerts the user when the waiting time is over
function rapidshare_domain_waitUntilReady(download){
  if (unsafeWindow.c) {
    unsafeWindow.c -= 5; // a little speedup
    pollFormCreation();
  }
  // Wait for the script to create the form
  function pollFormCreation() {
    if (document.forms.namedItem("dl")) download();
    else setTimeout(pollFormCreation, 2000);
  }
}
//***********************
// Alerts the user when the wait between downloads is over
function rapidshare_domain_waitToDownloadAgain(textData, download){
  var font = getFirstXPathResult("//*[contains(text(), '"+textData+"')]");
  if (!font) return;
  var p = font.parentNode;
  var minutes = 1;
  try { minutes = Number(p.textContent.match(/or wait (\d+) minutes?/i)[1]); } catch(e){};
  p.innerHTML += "<h3> If you keep this page open, you'll be alerted when you can download again.</h3>";
  // Create a span to hold the time ticker
  p.innerHTML = p.innerHTML.replace(/\d+ minutes?/i,
      "<span id='timer' style='font-weight: bold; color: grey; font-size: larger'></span> Minutes");
  var timeReady = new Date();
  timeReady.setMinutes(timeReady.getMinutes() + minutes);
  waitTimeoff();

	function waitTimeoff()  {
	  var now = new Date();
	  if (now < timeReady) {
	    var left = new Date(timeReady - now);
	    // Match hours only if not 00
	    var strTime = left.toUTCString().match(/(0[1-9]:)?\d\d:\d\d /)[0];
	    document.getElementById("timer").textContent = strTime;
	    if (putTimerInTitle) document.title = "RS (" + strTime + ")";
	    setTimeout(waitTimeoff, 1000);
	  }
	  else download();
  }
}
//***********************  rapidshare_domain  //***********************
function rapidshare(tld){
	if (tld!='com') 
	  if (tld!='de') return;
	try { findClick("//input[@value='Free']"); } catch(e){};
  rapidshare_domain_cleanDownloadPage();
  rapidshare_domain_waitUntilReady(download);
  rapidshare_domain_waitToDownloadAgain('Download ticket reserved', download);
  rapidshare_domain_waitToDownloadAgain('already downloading a File', history_back);
  rapidshare_domain_waitToDownloadAgain('reached the download-limit', history_back);
  function history_back(){
  	history.back();
  }
  function download(){
//    rapidshare_domain_prepareDownloadLink(); // removed because this no longer allows files to be downloaded
  	alert('Ready to download');
  }
}/*
function rapidshare(tld){
	if (tld!='com') 
	  if (tld!='de') return;
	try { findClick("//input[@value='Free']"); } catch(e){};
  rapidshare_domain_cleanDownloadPage();
  try { findDownload('Download ticket reserved', findReplaceEx, download); } catch(e){};
  try { findDownload('already downloading a File', findReplace, history.back); } catch(e){};
  try { findDownload('reached the download-limit', findReplace, history.back); } catch(e){};
  //***********************
  function download(){ alert('Ready to download'); }
  //***********************
  function findReplaceEx(p){
//		var x=document.body.innerHTML.replace(/\n/g, '').match(/(x\d+)=46/)[1];
//		unsafeWindow.setTimeout(x+'=1', 1);
//  	return 0;
	  var delayMinutes = 1;
	  try { delayMinutes = Number(p.getElementsByTagName("big")[2].textContent); } catch(e){};
		unsafeWindow.c=0;
		alert(p.innerHTML);
		alert(p.getElementsByTagName("big")[2].innerHTML);
	  p.getElementsByTagName("big")[2].innerHTML = p.getElementsByTagName("big")[2].innerHTML.replace(
	    p.getElementsByTagName("big")[2].textContent, 
      "<h3> If you keep this page open, you'll be alerted when you can download again.</h3>"+
	    "<span id='timer' style='font-weight: bold; color: grey; font-size: larger'>"+delayMinutes+"</span> Seconds");
  	return delayMinutes * 60;
  }
  //***********************
  function findReplace(p){
	  var delayMinutes = 1;
	  try { delayMinutes = Number(p.textContent.match(/or wait (\d+) minutes?/i)[1]); } catch(e){};
	  p.innerHTML = p.innerHTML.replace(/\d+ minutes?/i,
      "<h3> If you keep this page open, you'll be alerted when you can download again.</h3>"+
	    "<span id='timer' style='font-weight: bold; color: grey; font-size: larger'></span> Seconds ");
  	return delayMinutes * 60;
  }
  //***********************
  function findDownload(textData, findReplaceEvent, download){
//	  var font = getFirstXPathResult("//*[contains(text(), '"+textData+"')]");
	  if (!font) return;
	  var p = font.parentNode;	  
	  var delaySeconds = findReplaceEvent(p);
	  waitUntilReadyTest('timer', delaySeconds, 'RS', download)
  }
}*/
//***********************
function megaupload(tld, seconds, tabPrefix, idElement){
//2function megaupload(tld, seconds){	
	if (tld!='com') return;
	try {
		try {
  		var deleteElement = document.getElementById("filetag");
	  	deleteElement.parentNode.removeChild(deleteElement);
		} catch(e){};
		var x=document.body.innerHTML.replace(/\n/g, '').match(/(x\d+)=46/)[1];
		unsafeWindow.setTimeout(x+'=1', 1);
/*		try {
		  var box = document.getElementById("floatingbox");
	  	box.parentNode.removeChild(box);
  	} catch(e){};*/
		unsafeWindow.setTimeout(
    	function () {
//2			  var font = document.getElementById("download_html");
			  var font = document.getElementById(idElement);			  
			if (font) { var p = font.parentNode; }
			else {
//			  var seconds = 44; // passed to the function
//			  try { seconds = Number(p.textContent.match(/or wait (\d+) seconds?/i)[1]); } catch(e){ seconds = 44; };
        p = document.getElementById("starttext");        
        try { seconds = Number(p.textContent.match(/Please wait (\d+) minutes?/i)[1])*60; } catch(e){ seconds = 44; };
			}
			  p.innerHTML += "<h3> Do not click the above link unless the seconds counter is at 00:00.<BR/>If you keep this page open, it will automatically start the download for you.</h3>";
			  // Create a span to hold the time ticker
			  p.innerHTML += "Please wait <span id='timer' style='font-weight: bold; color: grey; font-size: larger'></span> Seconds";  

/*2				if (font) waitUntilReady('timer', seconds, 'MU', download)
				else waitUntilReady('timer', seconds, 'MU', historyBack);*/
				if (font) waitUntilReady('timer', seconds, tabPrefix, download)
				else waitUntilReady('timer', seconds, tabPrefix, historyBack);
				function historyBack(){
					history.back();
				}
    		function download(){
	  			var x=document.body.innerHTML.replace(/\n/g, '').match(/(x\d+)=46/)[1];
					unsafeWindow.setTimeout(x+'=1', 1);
//2		      document.location=document.getElementById("download_html").getElementsByTagName('a')[0];
		      document.location=document.getElementById(idElement).getElementsByTagName('a')[0];
        }
    }, 1000);
	} catch(e){};
}
//***********************
function depositfiles(tld){
	if (tld!='com') if (tld!='net') return;
  var urlLink = getFirstXPathResult("//span[@id='download_waiter_remain']");
	try { 
		if (!urlLink) { 
//			unsafeWindow.setTimeout(findClick("//input[@value='DOWNLOAD']"), 1500);			
			return;
		}
		var urlLink = getFirstXPathResult("//div[@class='attention']");
		if (urlLink) urlLink.textContent=urlLink.textContent+" -- You don't need to wait for the timer :)";
    document.getElementById("download_waiter_remain").innerHTML=0.2;		
    document.getElementsByTagName("script")[2].innerHTML='var dwnsrc = "#"\nshow_url(0.2);';
		unsafeWindow.show_url(0.2);	
		unsafeWindow.refresh();
	} catch(e){};
};
//***********************
function depositfiles_OLD(tld){
	if (tld!='com') if (tld!='net') return;
	try { 
//		findClick("//input[@value='DOWNLOAD']")  
	 var urlLink = getFirstXPathResult("//input[@value='DOWNLOAD']");
	 if (urlLink) {
	 	urlLink.onclick="alert('dude'); return false;";//"this.form.submit();return false;"
    urlLink.click();
  }
		return;
	} catch(e){}; // Added support for the header page if it exists
/*	try { 
		unsafeWindow.pass_gateway(0);	
	} catch(e){}; // Added support for the header page if it exists
*/
	try { 
		 download_bonus();
/*		 var urlLink = getFirstXPathResult("//input[@value='DOWNLOAD']");
		 alert(urlLink);
		 if (!urlLink) //findClick("//input[@id='request_button']")
		 urlLink.click();*/
//		findClick("//input[@value='DOWNLOAD']")  
	} catch(e){}; // Added support for the header page if it exists
	try { 
/*		unsafeWindow.begin_popup_url='';
		unsafeWindow.show_url_is_started = true;
		document.getElementById("download_waiter_remain").parentNode.style.display = 'none';
    document.getElementById('download_url').style.display = '';
    on_event('download_show_url_ended');*/
		document.getElementById("download_waiter_remain").innerHTML=0;		
//		document.location=unsafeWindow.dwnsrc;
		unsafeWindow.show_url(0);	
	} catch(e){};
};
//***********************
function mihd(tld){
	if (tld!='net') return;
	try { 
//		unsafeWindow.getTicket(); 
		 var urlLink = getFirstXPathResult("//a[contains(text(), 'Download')]");
		 if (!urlLink) unsafeWindow.requestTicket() //findClick("//input[@id='request_button']")
     else document.location=urlLink.parentNode.getElementsByTagName('a')[0];
	} catch(e){};	
};
//***********************
function filesend(tld){
	if (tld!='net') return;
	try { 
		unsafeWindow.time=0; 
		unsafeWindow.download();
//		document.getElementById('dl').getElementsByTagName('form')[0].submit;
    findClick("//input[@type='submit']");
	} catch(e){};	
}
//***********************
function badongo(tld){
	if (tld!='com') return;
	try { unsafeWindow.check_n=0; } catch(e){};
}
//***********************
function mytempdir(tld){
	if (tld!='com') return;
	try { unsafeWindow.setTimeout('loading()', 1); } catch(e){};
	unsafeWindow.setTimeout(
		function() {
			try { 
				document.location=document.getElementById('download').getElementsByTagName('table')[0].getElementsByTagName('a')[0]; 
			} catch(e){}
		}, 1);
}
//***********************
function bigupload(tld){
	if (tld!='com') return;
	try { unsafeWindow.count=1;	} catch(e){};
	unsafeWindow.setTimeout(
		function() {
			try { 
				var copyToken = document.getElementById('copyinp');
				if(!copyToken) {unsafeWindow.self_refresh();}
				else { 
					document.location = copyToken.parentNode.getElementsByTagName('font')[0].getElementsByTagName('b')[0].getElementsByTagName('a')[0].href;
				} 
			} catch(e){}
		}, 500);
}
//***********************
function yousendit(tld){
	if (tld!='com') return;
	try { document.location=document.getElementById("download-direct-link"); } catch(e){};
	try { document.location=document.getElementById("button-div").getElementsByTagName('a')[0]; } catch(e){};
}
//***********************
function live_share(tld, seconds) {
	if (tld!='com') return;
	try { unsafeWindow.waitingTime=1; } catch(e){};

	unsafeWindow.setTimeout(
		function() {			
		  var spanLink = document.getElementById("download_link");
		  if (!spanLink) return;
		  var p = spanLink.parentNode;
		  p.innerHTML += "<h3> Do not click the above link unless the seconds counter is at 00:00.<BR/>If you keep this page open, it will automatically start the download for you.";
			p.innerHTML += "<BR/>Please wait <span id='timer' style='font-weight: bold; color: grey; font-size: larger'>14</span> Seconds</h3>";  

//			var seconds = 14; // passed to the function
  		waitUntilReady('timer', seconds, 'LS', download);
  		function download(){
			  var spanLink = document.getElementById("download_link");
			  if (!spanLink) return;
			  document.location=spanLink.parentNode.getElementsByTagName('a')[0].href;
      }
		}, 1000);
}
//***********************
function fileho(tld){
	if (tld!='com') return;
	try { 
		document.location=document.getElementById("sh_link").getElementsByTagName('a')[0];
	} catch(e){};
};
//***********************
function oxyshare(tld){
	if (tld!='com') return;
  try { findClick("//input[@name='getfile']"); } catch(e){}	
	try { 		
		unsafeWindow.milisec=1;
		unsafeWindow.seconds=0;
		unsafeWindow.setTimeout(
			function() {			
				try { 
//					alert(document.getElementById("counter").getElementsByTagName('a')[0].href);
					document.location=document.getElementById("counter").getElementsByTagName('a')[0].href;
				} catch(e){}
			}, 1000);		
/*		if (aPath[1]=='get') document.getElementById("counter").parentNode.submit();
		else if (aPath[1]=='got') {
 		  unsafeWindow.milisec=1;
      unsafeWindow.seconds=0;
			unsafeWindow.setTimeout(
				function() {			
					try { 
						document.location=document.getElementById("counter").getElementsByTagName('a')[0].href;
					} catch(e){}
				}, 1000);
		}*/		
	} catch(e){};
}
//***********************
function turboupload(tld){
	if (tld!='com') return;
	try { unsafeWindow.ts=0; } catch(e){};
  unsafeWindow.setTimeout(
	  function() {
			try { 	  		
		    document.getElementById('div1').style.display= 'none';
		    document.getElementById('div2').style.display= '';	  	
			} catch(e){};	
	  	try { 	  		
        document.location=document.getElementById("wait").getElementsByTagName('b')[0].getElementsByTagName('a')[0].href;
//?        findClick("//a[contains(text(), 'Click here to download file')]");
			} catch(e){};	
	  }, 1500);		
}
//***********************
function mooload(tld){
	if (tld!='com') return;
//	try { findClick("//input[@value='Click Here To Download!']"); } catch(e){}
  unsafeWindow.setTimeout(
	  function() {
			try { 
		    var dataText = getFirstXPathResult("//b[contains(text(), 'DOWNLOAD LINK')]");
		    if (!dataText) return;
		    document.location=dataText.parentNode.getElementsByTagName('a')[0].href;
			} catch(e){};
	  }, 2000);	
}
//***********************
function icefile(tld){
  if (tld=='com') {
		try { 
			try { unsafeWindow.seconds=1; } catch(e){};
			var x=document.body.innerHTML.replace(/\n/g, '').match(/(x\d+)=30/)[1];
			unsafeWindow.setTimeout(x+'=1', 1);
		} catch(e){};
	  unsafeWindow.setTimeout(
		  function() {
			  try { findClick("//input[@value='Download File Now']"); } catch(e){}
		  }, 1000);
	}
	else try { unsafeWindow.seconds=1; } catch(e){}
}
//***********************
function quicksharing(tld){
	if (tld!='com') return;
	try { delayFindHREF(1000, "//*[contains(text(), 'Download')]", true);	} catch(e){};	
}
//***********************
function verzend(tld){
	if (tld!='be') return;
	try { unsafeWindow.t=0; } catch(e){};
  unsafeWindow.setTimeout(
	  function() {
			try { document.location=unsafeWindow.downloadlink; } catch(e){}
	  }, 1000);
}
//***********************
function megashares(tld){
	if (tld!='com') return;
	try { delayFindHREF(1000, "//a[contains(text(), 'Click here to download')]", false);	} catch(e){};
}
//***********************
function megashare(tld){
	if (tld!='com') return;
	try { unsafeWindow.c=0; } catch(e){};
  unsafeWindow.setTimeout(
	  function() {
			try { findClick("//input[@value='Click Here to Download']"); } catch(e){}
	  }, 1000);
	try { findClick("//input[@name='FreeDz']"); } catch(e){};
	try { findClick("//input[@name='yes']"); } catch(e){};
}
//***********************
function ftp2share(tld){
	if (tld!='com') return;
  try { 
  	var btn = findClick("//input[@value='Download']"); 
  	if(btn==null) {
  		btn = findClick("//input[@value='Link to File']"); 
    	return;
    }
		try { 
			unsafeWindow.milisec=1;
			unsafeWindow.seconds=0;
		} catch(e){};
	  unsafeWindow.setTimeout(
		  function() {
			  var urlLink = getFirstXPathResult("//a[contains(text(), 'DOWNLOAD your file')]");
			  if (!urlLink) return;  
		  	document.location = urlLink;
		  }, 1000);		
	}
  catch(e){}	
}
//***********************
function lix(tld){
	if (tld!='in') return;
  try { 
  	var btn = findClick("//input[@value='continue']"); 
  	if(btn!=null) return;  	
    var urlLink = getFirstXPathResult("//link[@rel='stylesheet']");
    if (urlLink) {
			var idx = urlLink.href.indexOf("://")+3; var sDomain = urlLink.href.substring(idx);
			var idx = sDomain.indexOf("/"); sDomain = sDomain.substring(0, idx);
			var aDomain = new Array(); aDomain = sDomain.split('.');
			switch(aDomain[aDomain.length-2].toLowerCase()){
				case 'rapidshare'   : rapidshare(   aDomain[aDomain.length-1].toLowerCase()); break;
			}    	
	  }
	}
  catch(e){}	
}
//***********************
function filefactory(tld){
	if (tld!='com') return;
  try { 
    var urlLink = getFirstXPathResult("//*[contains(text(), 'Download for free with FileFactory Basic')]");
	  if (urlLink) document.location = urlLink.parentNode.parentNode.getElementsByTagName('a')[1].href
  	else {
	  	urlLink = getFirstXPathResult("//*[contains(text(), 'Click here to begin your download')]");
	  	if (!urlLink) return;
		  document.location = urlLink.parentNode.parentNode.getElementsByTagName('a')[0].href;
	  }
	}
  catch(e){}	
}
//***********************
function sendspace(tld){
	if (tld!='com') return;
	try { unsafeWindow.count=1;	} catch(e){};
	unsafeWindow.setTimeout( 
		function() {			
//			alert('!! Not fully tested !!'); // ********************************************************************
		  var spanLink = document.getElementById("spndllink");
		  if (!spanLink) return;
		  var p = spanLink.parentNode;
		  p.innerHTML += "<h3> Do not click the above link unless the seconds counter is at 00:00.<BR/>If you keep this page open, it will automatically start the download for you.";
			p.innerHTML += "<BR/>Please wait <span id='timer' style='font-weight: bold; color: grey; font-size: larger'>14</span> Seconds</h3>";  

			var seconds = 9;// 60 passed to the function
  		waitUntilReady('timer', seconds, 'SS', download);
  		function download(){
			  var urlLink = document.getElementById("spndllink");
			  if (!urlLink) return;
			  document.location = urlLink.href;
//			  document.location=spanLink.parentNode.getElementsByTagName('a')[0].href;
      }
		}, 1000);
	try { 
	  unsafeWindow.setTimeout(
		  function() {
			  var urlLink = document.getElementById('downlink');
			  if (!urlLink) return;  			  
		  	document.location = urlLink.href;
		  }, 1000);		
	} catch(e){};
}
//***********************
function yofreespace(tld){
	if (tld!='com') return;
	try { unsafeWindow.timeout=0; } catch(e){};
  try {
	  unsafeWindow.setTimeout(
		  function() {
			  var urlLink = document.getElementById("downloadbtn");
			  if (!urlLink) return;
			  if (urlLink.getElementsByTagName('a')) document.location = urlLink.getElementsByTagName('a')[0].href
			  else {
  			  var urlLinkEx = getFirstXPathResult("//*[contains(text(), 'File server too busy')]");
	  		  if (urlLinkEx) unsafeWindow.setTimeout( function() { history.back(); }, 5000);
			  }
		  }, 1000);		
	} catch(e){};
}
//***********************
function gigasize(tld){
	if (tld!='com') return;
  try { findClick("//input[@id='dlb']"); } catch(e){};	
}
//***********************
function ileech(tld){
	if (tld!='net') return;
	var txtLink = getFirstXPathResult("//img[@alt='GO']");
	if (!txtLink) return;
	if(txtLink.parentNode.href) document.location = txtLink.parentNode.href;
}
//***********************
function rsprotect(tld){
	if (tld!='com') return;
  try { findClick("//input[@value='START DOWNLOAD']"); } catch(e){}	
}
//***********************
function zshare(tld){
	if (tld!='net') return;
	try { 		
		var txtLink = getFirstXPathResult("//form[@name='form1']");
		if (!txtLink) return;
		txtLink.submit();
	} catch(e){}	
}
//***********************
function mediafire(tld){
	if (tld!='com') return;
  unsafeWindow.setTimeout(
	  function() {
		  try { 
			  var urlLink = document.getElementById("download_link");
			  if (!urlLink) return;
			  document.location=urlLink.parentNode.getElementsByTagName('a')[0].href;
			} catch(e){}	
	  }, 1000);	
}
//***********************
function binfile(tld){
	if (tld!='org') return;
	try { unsafeWindow.timeout=0; } catch(e){}	
}
//***********************
function uploading(tld){
	if (tld!='com') return;
	try { 
		var x=document.body.innerHTML.replace(/\n/g, '').match(/(x\d+)=25/)[1];
		unsafeWindow.setTimeout(x+'=1', 1);
    document.getElementById("waitblock").style.display = 'none';
    document.getElementById("linkblock").style.display = '';
	} catch(e){};
  unsafeWindow.setTimeout(
	  function() {
		  try { 
        var dataText = getFirstXPathResult("//*[contains(text(), 'Click here to download')]");
        if (!dataText) return;
        document.location=dataText.parentNode.href;
      } catch(e){}
	  }, 1000);	
}
//***********************
function easy_share(tld){
	if (tld!='com') return;
  unsafeWindow.setTimeout(
	  function() {
			try { 
		    var dataText = getFirstXPathResult("//a[contains(text(), '.easy-share.com/')]");
		    if(!dataText) return;
		    document.location=dataText.href;
			} catch(e){};
	  }, 1000);	
}		
//***********************
function axifile(tld, seconds){
	if (tld!='com') return;
  unsafeWindow.setTimeout(
	  function() {
			try{
				var dataText = getFirstXPathResult("//a[contains(text(), 'dl.axifile.com')]");
				if(!dataText) return;
				document.location = dataText.href;
		  } catch(e){};
  }, (seconds+2)*1000);	
}
//***********************
function sharebigfile(tld){
	if (tld!='com') return;
	try{
	  unsafeWindow.timeout=0;
	  unsafeWindow.setTimeout(
		  function() {
				try { findClick("//input[@id='downloadbtn']"); } catch(e){};
		  }, ((unsafeWindow.timeout+1)*1000));	
	} catch(e){}
}
//***********************
function gulli(tld){
	if (tld!='com') return;
	try { 
		findClick("//input[@class='share_input_submit']");
	} catch(e){}
}
//***********************
function link_protector(tld){
	if (tld!='com') return;
  try { 
    var urlLink = getFirstXPathResult("//link[@rel='stylesheet']");
    if (urlLink) {
			var idx = urlLink.href.indexOf("://")+3; var sDomain = urlLink.href.substring(idx);
			var idx = sDomain.indexOf("/"); sDomain = sDomain.substring(0, idx);
			var aDomain = new Array(); aDomain = sDomain.split('.');
			switch(aDomain[aDomain.length-2].toLowerCase()){
				case 'rapidshare'   : rapidshare(   aDomain[aDomain.length-1].toLowerCase()); break;
			}    	
	  }
	}
  catch(e){}	
}
//***********************
function hyperupload(tld){
	if (tld!='com') return;
	try { 
		var x=document.head.innerHTML.replace(/\n/g, '').match(/(x\d+)=25/)[1];
//		alert(x);
		unsafeWindow.setTimeout(x+'=0', 1);
/*		unsafeWindow.setTimeout(
		  function(){
		  	var x=document.head.innerHTML.replace(/\n/g, '').match(/(x\d+)=0/)[1];
    		alert(x);
		  	alert(unsafeWindow.hmwh2);
		  }, 100);		  	*/
//		findClick("//input[@class='share_input_submit']");
	} catch(e){}
}
//***********************
function flyupload(tld){
	if (tld!='com') return;
	try { 
		if(aPath[1]!='thankyou'){
	    var urlLink = getFirstXPathResult("//A[contains(text(), 'Download')]");
			if (urlLink) {location.href=urlLink;}
	  }
		else {
//			if(aPath[1]='thankyou')
			try { 
				var urlLink = location.href.substring(location.href.indexOf("=")+1, 500);
//				alert(urlLink);
				if (urlLink) location.href=urlLink;		
			} catch(e){}
		}			
	} catch(e){}
}
//***********************
function mfile3(tld){
	if (tld!='com') return;
	try { 
    var urlLink = getFirstXPathResult("//a[text()='download']");
		if (urlLink) location.href=urlLink;		
	} catch(e){}
}
//***********************
function filefront(tld){
	if (tld!='com') return;
	try { 
    var urlLink = getFirstXPathResult("//div[@class='dlLeft']");
		if (urlLink) location.href=urlLink.getElementsByTagName('a')[0].href;		
	} catch(e){}
}
//***********************
function zupload(tld){
	if (tld!='com') return;
	try { 
//		findClick("//a[contains(@href, 'file.php?filepath=')]");
		var textLink = getFirstXPathResult("//a[contains(@href, 'file.php?filepath=')]");
		if (!textLink) return;
		alert(textLink.href);
		location.href=textLink.href;
	} catch(e){}
}
//***********************
function bravoshare(tld){
	if (tld!='com') return;
	try {
		var urlLink='X'+aPath[1];
		var idx = urlLink.indexOf("transfer.php"); 
		if(idx>0){ 
			var urlLink2=getDomain()+'/'+urlLink.substring(1, idx)+'bank.php';
			location.href=urlLink2;
		}
	} catch(e){}
}
//***********************
function urlcash(tld){
	if (tld!='net') return;
	try { 
    var urlLink = getFirstXPathResult("//a[contains(text(), 'wish to wait')]");
    if (urlLink) location.href=urlLink;
	} catch(e){}
}
//***********************  //***********************
var idx = location.href.indexOf("://")+3; var sDomain = location.href.substring(idx);
var idx = sDomain.indexOf("/"); sDomain = sDomain.substring(0, idx);
var aDomain = new Array(); aDomain = sDomain.split('.');
var aPath = new Array(); aPath = location.pathname.split('/');
//var aParameter = new Array(); aParameter = location.href.split('?');
try { putTimerInTitle = GM_getValue("timerInTitle", true); } catch (e){};
//***********************
switch(aDomain[aDomain.length-2].toLowerCase()){
	case 'badongo'      : badongo(      aDomain[aDomain.length-1].toLowerCase()); break;
	case 'bigupload'    : bigupload(    aDomain[aDomain.length-1].toLowerCase()); break;
	case 'filefactory'  : filefactory(  aDomain[aDomain.length-1].toLowerCase()); break;
	case 'fileho'       : fileho(       aDomain[aDomain.length-1].toLowerCase()); break;
	case 'filesend'     : filesend(     aDomain[aDomain.length-1].toLowerCase()); break;
	case 'ftp2share'    : ftp2share(    aDomain[aDomain.length-1].toLowerCase()); break;
	case 'gigasize'     : gigasize(     aDomain[aDomain.length-1].toLowerCase()); break;
	case 'icefile'      : icefile(      aDomain[aDomain.length-1].toLowerCase()); break;
	case 'ileech'       : ileech(       aDomain[aDomain.length-1].toLowerCase()); break;
	case 'live-share'   : live_share(   aDomain[aDomain.length-1].toLowerCase(), 14); break;
	case 'lix'          : lix(          aDomain[aDomain.length-1].toLowerCase()); break;
	case 'megashares'   : megashares(   aDomain[aDomain.length-1].toLowerCase()); break;
	case 'megashare'    : megashare (   aDomain[aDomain.length-1].toLowerCase()); break;
	case 'megaupload'   : megaupload(   aDomain[aDomain.length-1].toLowerCase(), 44, 'MU', "download_html"); break;
	case 'mihd'         : mihd(         aDomain[aDomain.length-1].toLowerCase()); break;
	case 'mooload'      : mooload(      aDomain[aDomain.length-1].toLowerCase()); break;
	case 'mytempdir'    : mytempdir(    aDomain[aDomain.length-1].toLowerCase()); break;
	case 'oxyshare'     : oxyshare(     aDomain[aDomain.length-1].toLowerCase()); break;
	case 'quicksharing' : quicksharing( aDomain[aDomain.length-1].toLowerCase()); break;
	case 'rapidshare'   : rapidshare(   aDomain[aDomain.length-1].toLowerCase()); break;
	case 'rsprotect'    : rsprotect(    aDomain[aDomain.length-1].toLowerCase()); break;
	case 'sendspace'    : sendspace(    aDomain[aDomain.length-1].toLowerCase()); break;
	case 'turboupload'  : turboupload(  aDomain[aDomain.length-1].toLowerCase()); break;
	case 'verzend'      : verzend(      aDomain[aDomain.length-1].toLowerCase()); break;
	case 'yofreespace'  : yofreespace(  aDomain[aDomain.length-1].toLowerCase()); break;
	case 'yousendit'    : yousendit(    aDomain[aDomain.length-1].toLowerCase()); break;
	case 'zshare'       :	zshare(       aDomain[aDomain.length-1].toLowerCase()); break;
	case 'binfile'      :	binfile(      aDomain[aDomain.length-1].toLowerCase()); break;	
	case 'uploading'    : uploading(    aDomain[aDomain.length-1].toLowerCase()); break;
	case 'easy-share'   : easy_share(   aDomain[aDomain.length-1].toLowerCase()); break;
	case 'axifile'      : axifile(      aDomain[aDomain.length-1].toLowerCase(), 35); break;
	case 'sharebigfile' : sharebigfile( aDomain[aDomain.length-1].toLowerCase()); break;
	case 'megarotic'    : megaupload(   aDomain[aDomain.length-1].toLowerCase(), 44, 'ME', "downloadhtml");break;
	case 'looler'       : sharebigfile( aDomain[aDomain.length-1].toLowerCase()); break;
	case 'mediafire'    : mediafire(    aDomain[aDomain.length-1].toLowerCase()); break;
	case 'gulli'        :	gulli(        aDomain[aDomain.length-1].toLowerCase()); break;
	case 'hyperupload'  : hyperupload(  aDomain[aDomain.length-1].toLowerCase()); break;
	case 'link-protector': link_protector( aDomain[aDomain.length-1].toLowerCase()); break;
	case 'flyupload'    : flyupload(    aDomain[aDomain.length-1].toLowerCase()); break;
	case 'mfile3'       : mfile3(       aDomain[aDomain.length-1].toLowerCase()); break;
	case 'filefront'    :	filefront(    aDomain[aDomain.length-1].toLowerCase()); break;
	case 'urlcash'      :	urlcash(      aDomain[aDomain.length-1].toLowerCase()); break;
  case 'depositfiles' : depositfiles( aDomain[aDomain.length-1].toLowerCase()); break;
/* PARTLY FIXED */	case 'bravoshare'   :	bravoshare(   aDomain[aDomain.length-1].toLowerCase()); break;
//* NOT FIXED YET */	case 'zupload': zupload(aDomain[aDomain.length-1].toLowerCase()); break;
}
//***********************  //***********************
